// Copyright (C) 2010 and onwards Harik Shazeer Labs
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Authors: Noam Shazeer and Georges Harik

#ifndef _OBJECTSTORE_H_
#define _OBJECTSTORE_H_

#include "interpret.h"
#include "records.h"
#include "allocator.h"

enum MessageType {
  ARRAY_MESSAGE,
  UNBOXED_OBJECT_MESSAGE,
};

struct ObjectStore : public AllocatorDependant {
  ObjectStore(string fn);

  void Read(ThreadAllocator * ta);
  
  void WriteObject(Object *o);
  
  Object * HashToObject(uint64 h);
  
  int32 NumShards() {return 1;}
  void FlagReferences(int32 shard, Frontier *frontier);
  void ObjectsDeleted(int32 shard);

 private:
  void InsertNewObject(Object *o);

  hash_map<uint64, Object *, SimpleHash<uint64> > hash_object_;

  int64 object_count_;
  
  RecordFile file_;
};

#endif
